<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-L-admin1.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="../static/TG_logo.jpg" type="image/x-icon" />
    <link rel="stylesheet" href="../static/css/font.css">
    <link rel="stylesheet" href="../static/css/xadmin.css">
    <script src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../static/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
    <div class="x-body">
        <form class="layui-form">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>商品标题
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="title" required lay-verify="" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>商品分类
                </label>
                <div class="layui-input-inline">
                    <select name="contrller" class="valid">
                        <option value="0">请选择</option>
                        <option value="1">DNF</option>
                        <option value="2">源神</option>
                        <option value="3">王者荣耀</option>
                        <option value="4">英雄联盟</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_pass" class="layui-form-label">
                    <span class="x-red">*</span>卖家姓名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="L_pass" id="sellername" required lay-verify="" autocomplete="off"
                        class="layui-input">
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label for="desc" class="layui-form-label">
                    描述
                </label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入内容" id="desc" name="desc" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>价格
                </label>
                <div class="layui-input-inline">
                    <input id="price" required lay-verify="number" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>库存
                </label>
                <div class="layui-input-inline">
                    <input id="quantity" required lay-verify="number" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                </label>
                <button class="layui-btn" onclick="revise()">
                    确定
                </button>
            </div>
        </form>
    </div>

</body>
<script>

    layui.use(['form', 'layer', 'laydate'], function () {
        var $ = layui.jquery;
        var form = layui.form;
        var layer = layui.layer;
        var laydate = layui.laydate;
    });



    var user = window.localStorage.getItem('TGshop_admin')
    function revise() {
        // jquery的方式
        var title = $('#title').val();
        var sort = $('select').val();
        var sellername = $('#sellername').val();
        var desc = $("textarea[name='desc']").val();
        var price = $("#price").val();
        var quantity = $("#quantity").val();
        var params = {
            "title": title,
            "sellername": sellername,
            "sort": sort,
            "price": price,
            " desc": desc,
            "quantity": quantity
        }
        // console.log(params);
        // 发送ajax请求
        $.ajax({
            url: 'http://127.0.0.1:8000/v1/TGadmin/commodity/' + user,
            type: 'put',
            data: JSON.stringify(params),
            contentType: 'application/json',
            datatype: JSON,
            beforeSend: function (request) {
                    request.setRequestHeader("authorization", localStorage.getItem('TGshop_token'))
                },
            success: function (data) {
                if (data.code == 403) {
                    alert(data.error)
                }
                if (data.code == 200) {
                    alert('修改成功');
                }
            }
        })
    }
</script>

</html>